﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Server
{
    class Room
    {
        public string m_name;
        public List<User> m_users;
        public Room(User creator, string name)
        {
            m_name = name;
            m_users = new List<User>();
            m_users.Add(creator);
        }
        public void Join(User user, string name)
        {
            m_name = name;
            m_users = new List<User>();
            m_users.Add(user);
        }
        public void broadcast(string msg)
        {
            for (int i = 0; i < m_users.Count(); i++)
            {
                m_users[i].SendMsgToClient(msg);
            }
        }
        public bool addUser(User user)
        {
            for (int i = 0; i < m_users.Count; i++)
            {
                if (m_users[i] == user)
                {
                    user.SendMsgToClient("you are already in the room: " + m_name);
                    return false;
                }
            }
            m_users.Add(user);
            return true;
        }
        public bool removeUser(User user)
        {
            for (int i = 0; i < m_users.Count; i++)
            {
                if (m_users[i] == user)
                {
                    m_users.RemoveAt(i);
                    return true;
                }
            }
            return false;
        }
    }
}
